//
//  MKAPIDictionary.h
//  MKAPI
//  对NSDictionary进行封装，可以使用a.b.c的方式操作dict数据
//  Created by 苏尚进 on 2022/8/26.
//  Copyright © 2022 moon. All rights reserved.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface MKAPIDictionary : NSObject<NSCopying>
@property(nonatomic,readonly) NSUInteger count;
- (id)initWithDictionary:(NSDictionary<NSString *,id> *)dictionary;
/// 返回字典对象
@property(nonatomic,readonly) NSDictionary<NSString *,id> *dictionary;

/// 设置值，支持以下方式：
///
// MKAPIDictionary *keyValuesParam = [MKAPIDictionary new];
//MKAPIDictionary.P(@"name", @"abc")
//.P(@"obj", [NSObject new])
//.P(@"flag", @(YES))
//.P(@"count", @10)
//.P(@"date", [NSDate date])
//.P(@"out", @"out")
//.P(@"out", nil)
//.P(@"array", @[@1,@2])
//.P(@"dict", @{@"a":@"1",@"b":@"2"})
//.P(@"set", [NSSet setWithArray:@[@1,@2]])
//.P(@"a.b.c", @"0")  =>  {"a":{"b":{"c":"0"}}}
//.P(@"a.0.c.1", @"1")
typedef MKAPIDictionary *_Nonnull(^MKAPIDictionaryBlock)(NSString *k,id _Nullable v);
@property(nonatomic,readonly) MKAPIDictionaryBlock P;
@property(nonatomic,class,readonly) MKAPIDictionaryBlock P;


typedef MKAPIDictionary *_Nonnull(^MKAPIDictionaryBlockS)(NSDictionary *_Nullable v);
@property(nonatomic,readonly) MKAPIDictionaryBlockS PS;
@property(nonatomic,class,readonly) MKAPIDictionaryBlockS PS;

/// 添加字典
/// @param dictionaryParam 字典
- (void)addDictionary:(NSDictionary<NSString *,id> *)dictionaryParam;

/// 移除所有数据
- (void)removeAll;

//支持以下方式：
//MKAPIDictionary *keyValuesParam = [MKAPIDictionary new];//keyValuesParam.dictionary为{}
//keyValuesParam[@"a.b.c"] = @"0";//keyValuesParam.dictionary将变成为{"a":{"b":{"c":"0"}}}
//id value = keyValuesParam[@"a.b.c"];//value=@"0"
//keyValuesParam[@"a.b.c"] = nil;//代表删除,此时keyValuesParam.dictionary将变成为{"a":{"b":{}}}
- (nullable id)objectForKeyedSubscript:(NSString *)key;
- (void)setObject:(nullable id)obj forKeyedSubscript:(NSString *)key;
@end

@interface MKAPIDictionary(KeyValueUrlEncode)
@property(nonatomic,readonly) NSString *keyValuesUrlEncodeString;//输出urlencode的字符串，如 k1=v1&k2[]=v2&k2[]=v22&k3[a1]=v3&k3[a2]=v33
@end

@interface MKAPIDictionary(NSMutableURLRequest)
- (void)setHTTPHeaderFieldToRequest:(NSMutableURLRequest *)request;
@end
NS_ASSUME_NONNULL_END
